/*
 * VirtualMachine.h
 *
 *  Created on: Nov 10, 2010
 *      Author: dhovemey
 */

#ifndef VIRTUALMACHINE_H_
#define VIRTUALMACHINE_H_

#include <string>
#include <map>
#include <vector>
#include "runtime/Object.h"
class ClassPath;
class Class;
class Arena;
class ASTNode;
class Reader;

class VirtualMachine {
private:
	typedef std::map<std::wstring, Class *> ClassNameToClassMap;
	typedef std::vector<Class *> ClassIdToClassMap;

	ClassPath *m_clsPath;
	Arena *m_arena;
	ClassNameToClassMap m_clsNameToClassMap;
	ClassIdToClassMap m_clsIdToClsMap;

	VirtualMachine(const VirtualMachine &);
	VirtualMachine& operator=(const VirtualMachine &);

public:
	VirtualMachine(ClassPath *clsPathToAdopt);
	virtual ~VirtualMachine();

	bool bootstrap();

	Class *findClass(const std::wstring &clsName);
	Class *loadClass(const std::wstring &clsName);
	bool loadSourceFile(Reader *reader, const std::string &fileName);
	Class *getClassForClassId(ClassId clsId);


private:
	Object *alloc(ClassId clsId);
	static unsigned getClassOrModuleFlags(ASTNode *clsOrModule);
};

#endif /* VIRTUALMACHINE_H_ */
